#include "adjust.h"

Adjust::Adjust(QWidget *parent)
    : QToolButton(parent)
{
    // 设置微调按钮的样式
    this->setPopupMode(QToolButton::InstantPopup);
    this->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
    this->setIcon(QIcon(":/icon/change.png"));
        m_popup_widget = new QWidgetAction(this);
        m_menu = new QMenu(this);

        QPointer<QListWidget> lwd = new QListWidget;
        lwd->setMinimumSize(QSize(620,520));
        lwd->setViewMode(QListView::IconMode);
        lwd->setIconSize(QSize(80, 80));


        QListWidgetItem* pListWIdgetItem = new QListWidgetItem;
        pListWIdgetItem->setSizeHint(QSize(600,500));
        lwd->addItem(pListWIdgetItem);

        //这是有关于人眼方向的设置
        QLabel* PeoDir = new QLabel("人眼方向");
        QPushButton* zhengshi = new QPushButton("正视图");
        QPushButton* back = new QPushButton("背视图");
        QPushButton* over = new QPushButton("俯视图");
        QPushButton* left = new QPushButton("左视图");
        QPushButton* right = new QPushButton("右视图");
        //这是有关于人眼视角调节的设置
        QSlider* changex = new QSlider(Qt::Horizontal);
        QSlider* changey = new QSlider(Qt::Horizontal);
        QSlider* changez = new QSlider(Qt::Horizontal);
        changex->setTickInterval(2);
        changey->setTickInterval(2);
        changez->setTickInterval(2);
        changex->setTickPosition(QSlider::TicksBelow);
        changey->setTickPosition(QSlider::TicksBelow);
        changez->setTickPosition(QSlider::TicksBelow);
        changex->setMaximum(200);
        changey->setMaximum(200);
        changez->setMaximum(200);
        changex->setTracking(true);
        changey->setTracking(true);
        changez->setTracking(true);
        changex->setValue(100);
        changey->setValue(100);
        changez->setValue(100);
        double one = 1.00;
        double hundred =100;
        xp_double = 0 ;
        yp_double = 0 ;
        zp_double = 0 ;
        peoplex=new QLabel;
        peopley=new QLabel;
        peoplez=new QLabel;
        Setpeoplexyz();
        //这是有关于光照方向的设置
        QLabel* LightDir = new QLabel("光照方向");
        QPushButton* lightfront = new QPushButton("前方");
        QPushButton* lightbehind = new QPushButton("后方");
        QPushButton* lightover = new QPushButton("上方");
        QPushButton* lightleft = new QPushButton("左侧");
        QPushButton* lightright = new QPushButton("右侧");


        //这是有关于光照方向调节的设置
        QSlider* changelx = new QSlider(Qt::Horizontal);
        QSlider* changely = new QSlider(Qt::Horizontal);
        QSlider* changelz = new QSlider(Qt::Horizontal);
        changelx->setTickInterval(2);
        changely->setTickInterval(2);
        changelz->setTickInterval(2);
        changelx->setTickPosition(QSlider::TicksBelow);
        changely->setTickPosition(QSlider::TicksBelow);
        changelz->setTickPosition(QSlider::TicksBelow);
        changelx->setMaximum(200);
        changely->setMaximum(200);
        changelz->setMaximum(200);
        changelx->setTracking(true);
        changely->setTracking(true);
        changelz->setTracking(true);
        changelx->setValue(100);
        changely->setValue(100);
        changelz->setValue(100);
        lxp_double = 0 ;
        lyp_double = 0 ;
        lzp_double = 0 ;
        lightx = new QLabel;
        lighty = new QLabel;
        lightz = new QLabel;
        Setlightxyz();


        QWidget *w = new QWidget;
        QGridLayout * layout = new QGridLayout;
        layout->addWidget(PeoDir,0,0,1,1);
        layout->addWidget(zhengshi,0,1,1,1);
        layout->addWidget(back,0,2,1,1);
        layout->addWidget(over,0,3,1,1);
        layout->addWidget(left,0,4,1,1);
        layout->addWidget(right,0,5,1,1);

        layout->addWidget(peoplex,1,0,1,1);
        layout->addWidget(peopley,2,0,1,1);
        layout->addWidget(peoplez,3,0,1,1);
        layout->addWidget(changex,1,1,1,5);
        layout->addWidget(changey,2,1,1,5);
        layout->addWidget(changez,3,1,1,5);

        layout->addWidget(LightDir,4,0,1,1);
        layout->addWidget(lightfront,4,1,1,1);
        layout->addWidget(lightbehind,4,2,1,1);
        layout->addWidget(lightover,4,3,1,1);
        layout->addWidget(lightleft,4,4,1,1);
        layout->addWidget(lightright,4,5,1,1);

        layout->addWidget(lightx,5,0,1,1);
        layout->addWidget(lighty,6,0,1,1);
        layout->addWidget(lightz,7,0,1,1);
        layout->addWidget(changelx,5,1,1,5);
        layout->addWidget(changely,6,1,1,5);
        layout->addWidget(changelz,7,1,1,5);



        w->setLayout(layout);
        w->setWindowIcon(QIcon(":/icon/change.png"));
        w->setWindowTitle("微调");


        lwd->setItemWidget(pListWIdgetItem,w);


        QPointer<QVBoxLayout> layout_main = new QVBoxLayout;
        layout_main->addWidget(lwd);
        QPointer<QWidget> default_widget = new QWidget;
        default_widget->setLayout(layout_main);
        m_popup_widget->setDefaultWidget(default_widget);

        m_menu->addAction(m_popup_widget);
        this->setMenu(m_menu);

        connect(changex,&QSlider::valueChanged,this,[=]{
            double cx = changex->value();
            xp_double = cx/hundred -one;
            Setpeoplexyz();
        });
        connect(changey,&QSlider::valueChanged,this,[=]{
            double cy = changey->value();
            yp_double = cy/hundred -one;
            Setpeoplexyz();
        });
        connect(changez,&QSlider::valueChanged,this,[=]{
            double cz = changez->value();
            zp_double = cz/hundred -one;
            Setpeoplexyz();
        });
        connect(zhengshi, &QPushButton::clicked, this, [=]{
            xp_double = 1;
            yp_double = 0;
            zp_double = 0;
            Setpeoplexyz();
            double cx = 200;
            double cy = 100;
            double cz = 100;
            changex->setValue(cx);
            changey->setValue(cy);
            changez->setValue(cz);

        });
        connect(over, &QPushButton::clicked, this, [=]{
            xp_double = 0;
            yp_double = 0;
            zp_double = 1;
            Setpeoplexyz();
            double cx = 100;
            double cy = 100;
            double cz = 200;
            changex->setValue(cx);
            changey->setValue(cy);
            changez->setValue(cz);
        });
        connect(back, &QPushButton::clicked, this, [=]{
            xp_double = -1;
            yp_double = 0;
            zp_double = 0;
            Setpeoplexyz();
            double cx = 0;
            double cy = 100;
            double cz = 100;
            changex->setValue(cx);
            changey->setValue(cy);
            changez->setValue(cz);

        });
        connect(left, &QPushButton::clicked, this, [=]{
            xp_double = 0;
            yp_double = -1;
            zp_double = 0;
            Setpeoplexyz();
            double cx = 100;
            double cy = 0;
            double cz = 100;
            changex->setValue(cx);
            changey->setValue(cy);
            changez->setValue(cz);

        });
        connect(right, &QPushButton::clicked, this, [=]{
            xp_double = 0;
            yp_double = 1;
            zp_double = 0;
            Setpeoplexyz();
            double cx = 100;
            double cy = 200;
            double cz = 100;
            changex->setValue(cx);
            changey->setValue(cy);
            changez->setValue(cz);
        });
        connect(changelx,&QSlider::valueChanged,this,[=]{
            double cx = changelx->value();
            lxp_double = cx/hundred -one;
            Setlightxyz();
        });
        connect(changely,&QSlider::valueChanged,this,[=]{
            double cy = changey->value();
            lyp_double = cy/hundred -one;
            Setlightxyz();
        });
        connect(changelz,&QSlider::valueChanged,this,[=]{
            double cz = changez->value();
            lzp_double = cz/hundred -one;
            Setlightxyz();
        });
        connect(lightfront, &QPushButton::clicked, this, [=]{
            lxp_double = 1;
            lyp_double = 0;
            lzp_double = 0;
            Setlightxyz();
            double cx = 200;
            double cy = 100;
            double cz = 100;
            changelx->setValue(cx);
            changely->setValue(cy);
            changelz->setValue(cz);

        });
        connect(lightover, &QPushButton::clicked, this, [=]{
            lxp_double = 0;
            lyp_double = 0;
            lzp_double = 1;
            Setlightxyz();
            double cx = 100;
            double cy = 100;
            double cz = 200;
            changelx->setValue(cx);
            changely->setValue(cy);
            changelz->setValue(cz);
        });
        connect(lightbehind, &QPushButton::clicked, this, [=]{
            lxp_double = -1;
            lyp_double = 0;
            lzp_double = 0;
            Setlightxyz();
            double cx = 0;
            double cy = 100;
            double cz = 100;
            changelx->setValue(cx);
            changely->setValue(cy);
            changelz->setValue(cz);

        });
        connect(lightleft, &QPushButton::clicked, this, [=]{
            lxp_double = 0;
            lyp_double = -1;
            lzp_double = 0;
            Setlightxyz();
            double cx = 100;
            double cy = 0;
            double cz = 100;
            changelx->setValue(cx);
            changely->setValue(cy);
            changelz->setValue(cz);

        });
        connect(lightright, &QPushButton::clicked, this, [=]{
            lxp_double = 0;
            lyp_double = 1;
            lzp_double = 0;
            Setlightxyz();
            double cx = 100;
            double cy = 200;
            double cz = 100;
            changelx->setValue(cx);
            changely->setValue(cy);
            changelz->setValue(cz);
        });
}

Adjust::~Adjust()
{
}

void Adjust::Setpeoplexyz()
{
    QString xp_str = QString("x= %1").arg(xp_double);
    peoplex->setText(xp_str);
    QString yp_str = QString("y= %1").arg(yp_double);
    peopley->setText(yp_str);
    QString zp_str = QString("z= %1").arg(zp_double);
    peoplez->setText(zp_str);
}

void Adjust::Setlightxyz()
{
    QString lxp_str = QString("x= %1").arg(lxp_double);
    lightx->setText(lxp_str);
    QString lyp_str = QString("y= %1").arg(lyp_double);
    lighty->setText(lyp_str);
    QString lzp_str = QString("z= %1").arg(lzp_double);
    lightz->setText(lzp_str);
}

